#include "Gobj.h"
#ifndef GOBJ_H
#define GOBJ_H

Gobj::~Gobj()
{
}
Gobj::Gobj(SDL_Surface * img, Point2d pos) //thua ke Gobj.h delay ham diem anh
{
	position.x = pos.x;
	position.y = pos.y;
	image = img;
	bound.x = pos.x;
	bound.y = pos.y;
	bound.w = img->w;
	bound.h = img->h;
}
void Gobj::Update()//update diem anh
{
	bound.x = position.x;
	bound.y = position.y;
}
SDL_Rect Gobj::getBox()//get diem anh
{
	bound.x = position.x;
	bound.y = position.y;
	bound.w = this->image->w;
	bound.h = this->image->h;
	return bound;
}
void Gobj::SetPosition(Point2d pos)//set point
{
	position.x = pos.x;
	position.y = pos.y;
}
void Gobj::Move(int dx, int dy)//di chuyen
{
	position.x += dx;
	position.y += dy;

	if (position.x > WITCH - image->clip_rect.w)
	{
		position.x = WITCH - image->clip_rect.w;
	}
	else if (position.x < 0)
	{
		position.x = 0;
	}

}
void Gobj::Draw(SDL_Surface*screen)//ve anh
{
	SDL_BlitSurface(this->image, NULL, screen, &bound);
}
bool Gobj::checkCollision(SDL_Rect A, SDL_Rect B)//kiem tra roi vao ro
{
	int leftA, leftB;
	int rightA, rightB;
	int topA, topB;
	int botA, botB;

	leftA = A.x;
	rightA = A.x + A.w;
	topA = A.y;
	botA = A.y + A.h;

	leftB = B.x;
	rightB = B.x + B.w;
	topB = B.y;
	botB = B.y + B.h;

	if (botA > topB &&  rightA < rightB && leftA > leftB)
	{
		return true;
	}
	else return false;
}
#endif